package cn.hdu.liang.ch4;

public class ForceMaxSub {
    public static void main(String[] args) {
        int[] a = {13, -3, -25, 20,
                -3, -16, -23, 18,
                20, -7, 12, -5,
                -22, 15, -4, 7};
        int start = 0, end = 0, sum = Integer.MIN_VALUE;
        int temp;
        for(int i = 0; i < a.length; i++) {
            temp = 0;
            for(int j = i; j < a.length; j++) {
                temp += a[j];
                if(temp > sum) {
                    sum = temp;
                    start = i;
                    end = j;
                }
            }
        }
        System.out.println("起始位置 : " + start);
        System.out.println("结束位置 : " + end);
        System.out.println("最大和   : " + sum);
    }
}
